// 评论表
const { DataTypes } = require("sequelize");
const sequelize = require("../db/connect");
const { Good } = require("./good");
const { AppUser } = require("./appUser");
const Comment = sequelize.define("comment", {
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    primaryKey: true,
  },
  //用户id
  appUserId: {
    type: DataTypes.INTEGER,
    allowNull: false,
  },
  //商品id
  goodId: {
    type: DataTypes.INTEGER,
    allowNull: false,
  },
  detail: {
    type: DataTypes.STRING,
    allowNull: false,
  },
  createdAt: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
  },
  updatedAt: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW,
    updataValue: DataTypes.NOW,
  },
});

Good.hasMany(Comment);
Comment.belongsTo(Good);

AppUser.hasMany(Comment);
Comment.belongsTo(AppUser);

module.exports = {
  Comment,
};
